<?php
include 'check_elapsed_event.php';
sec_session_start ();
if (isset ( $_COOKIE ['login_string'] )) {
	$login_string = $_COOKIE ['login_string'];
	$username = $_COOKIE ['username'];
	$user_id = $_COOKIE ['user_id'];
	
	$_SESSION ['user_id'] = $user_id;
	$_SESSION ['login_string'] = $login_string;
	$_SESSION ['username'] = $username;
}
if (login_check ( $mysqli ) == true) {
	$username = $_SESSION ['username'];
	global $ruolo;
	$query_ruolo="SELECT ruolo, saldo FROM members WHERE username='".$username."' LIMIT 1";
	if ($result = $mysqli->query ($query_ruolo )) {
		while ( $row = $result->fetch_assoc () ) {
			$ruolo=$row['ruolo'];
			$saldo=$row['saldo'];
		}
		$result->free();
	}
	//$data_corrente=date('Y-m-d H:i:s',time());
	
?>

<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Homepage</title>

<style>
@media (max-width: @screen-xs-max) { 
	#saldo{
	position:relative;
	left:80px;

	}
 }
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { #saldo{
	position:relative;
	left:80px;

	}
}
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) { ... }
@media (min-width: @screen-lg-min) { ... }
#referent_panel{
	font-family: Monaco;
	padding-bottom: 30px;
}
#ricarica1{
background:white;
color:black;
}
#ricarica2{
background:white;
color:black;
}

#saldo_piccoli_schermi{
	position:relative;
	left:400px;
	top:-210px;
}

#saldo_schermi_molto_piccoli{
	position:relative;
	top:-20px;
	left:35%;
}

</style>
<!-- Bootstrap -->
<link href="../css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery (necessario per i plugin Javascript di Bootstrap) -->
<script src="../js/jquery_1_11_2.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/general.js"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js non funziona se guardate la pagina attraverso file:// -->
<!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

<script type="text/javascript">
	function check_role(){
		
		var ruolo="<?php echo $ruolo;?>";
		if (ruolo=='so'){
			disable_admin();
			disable_referent();
		}
		if (ruolo=='re')
			disable_admin();
	}
	function disable_admin(){
		a=document.getElementsByName("to_dis");
		var i;
		for(i=0;i<a.length;i++)	
			a.item(i).setAttribute('disabled','disabled');
	}
	function disable_referent(){
			ref=document.getElementById('referent_panel');
			listItem=ref.childNodes;
					
		var s;
		for(s=0;s<listItem.length;s++){
			if(listItem.item(s).nodeName=='A')
			listItem.item(s).setAttribute("class","list-group-item disabled");
		}
	}
	function check_label_saldo(){
		labelsaldos=document.getElementsByName("label_saldo");
		
		var q;
		for (q=0;q<labelsaldos.length;q++){
			
			if(parseFloat(labelsaldos.item(q).firstChild.nodeValue)<2.50)
				labelsaldos.item(q).setAttribute("class","label label-danger");
		}
	}
</script>
</head>
<body onload="check_label_saldo()">
	
	<!-- 	barra di navigazione -->
	<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
		<div class="container">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed"
					data-toggle="collapse" data-target="#menu_links">
					<span class="sr-only">Toggle navigation</span> <span
						class="icon-bar"></span> <span class="icon-bar"></span> <span
						class="icon-bar"></span>
				</button>
				<a href="./home.php"><img src="../images/logo.png" height=45px
					width=45px></a>
			</div>
			<div class="collapse navbar-collapse" id=menu_links>
				<ul class="nav navbar-nav">
					<li class="active"><a href="./home.php"><span
							class="glyphicon glyphicon-home" aria-hidden="true"></span>&nbsp;Home</a></li>
					<li><a href="profile.php">Profile</a></li>
					<li><a href="#messaggi" onclick="richiedi('../messages/message.php');"
						data-toggle="tab">Messaggi</a></li>
				</ul>
				<p class="navbar-text navbar-right">
					Signed in as <a href="#" class="navbar-link"><mark><?php echo $username?></mark></a>&nbsp;&nbsp;&nbsp;<a
						href="../login/logout.php" class="navbar-link"><span
						class="glyphicon glyphicon-log-out" aria-hidden="true"></span>Logout</a>
				</p>
	
	</nav>
	</div>
	</nav>
	<!--   	contenitore della home -->
	
	<div class=container>
		<div class="page-header visible-lg-inline hidden-sm">
  <h1>Benvenuti in <small>CONTOGAS</small></h1>
</div>
		<div class=row>
			<div class="col-xs-12 col-md-9 col-sm-10">
				<!-- sezione ordini attivi -->
				<div name="ORDINI" id=orders class="panel panel-primary">
					<div class="panel-heading">
						<h1 class="panel-title">ORDINI ATTIVI</h1>
					</div>
					<div class="panel-body">
					<?php
							$query = "SELECT vendors.appellative,vendors.product_type, fin_date FROM orders INNER JOIN vendors ON vendors.id_vendor=orders.vendor WHERE orders.active=1 ORDER BY orders.fin_date";
							if ($result = $mysqli->query ($query )) {
								echo "<table class='table table-bordered info'>
								<tr><th align=center>FORNITORE<th align=center>TIPO MERCE<th align=center>SCADENZA</tr>";
								/* fetch associative array */
								while ( $row = $result->fetch_assoc () ) {
									echo "<tr class=info><td>",$row['appellative'],"<td>",$row['product_type'],"<td>",$row['fin_date'],"<td align=center><button type='button' class='btn btn-info btn-sm'>esegui</button></tr>";
								}
								echo "</table>";
								/* free result set */
								//$result->free ();
							}
					?>
					</div>
				</div>
				<!-- 	fine pannello ordini -->

				<!-- 				pannello di amministrazione -->
				<div name="AMMINISTRAZIONE" class="panel panel-warning">
					<div class="panel-heading">
						<h3 class="panel-title">Control Panel</h3>
					</div>
					<div class="panel-body">
						<div class=row>
							<div class="col-lg-6 col-xs-12 col-md-6 col-sm-6">
								<div class="btn-group btn-group-justified">
									<div class="btn-group">
										<button name=to_dis type="button" class="btn btn-default"><span class="glyphicon glyphicon-hand-right" aria-hidden="true"> Pagamenti</span></button>
									</div>
									<div class="btn-group">
										<button name=to_dis type="button" onclick="window.location='../registration/registrationform.php'" class="btn btn-warning">Inserimento
											Utenti</button>
									</div>

								</div>
							</div>
							<div class="col-lg-6 col-xs-12 col-md-6 col-sm-6">
								<div class="btn-group btn-group-justified">
									<div class="btn-group">
										<button type="button" name=to_dis class="btn btn-default">Gestione
											Fornitori</button>
									</div>
									<div class="btn-group">
										<button type="button" name=to_dis class="btn btn-warning"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> Gestione Soci</button>
									</div>
								</div>
							</div>
						</div>
					</div>
					<!-- fine del pannello di amministrazione -->
				</div>
			</div>
			<!-- chiusura pannello sinistro (1ma colonna del contenitore della home-->

			<!-- 			sezione gestione listini ed ordini ultimati-->
			<div id=right_panel class="col-xs-12 col-md-3 col-sm-6">
				<section class=list-group id=referent_panel>
					<a href="./catalog_management.php" class="list-group-item">
						<h4 class="list-group-item-heading list-group-item-success">GESTIONE
							LISTINI</h4>
						<p class="list-group-item-text">Crea un listino per ogni fornitore</p>
					</a> <a href="#" class="list-group-item">
						<h4 class="list-group-item-heading list-group-item-success">NUOVO
							ORDINE</h4>
						<p class="list-group-item-text">
							Inizia un nuovo ordine al<br> quale tutti i soci posso
							partecipare
						</p>
					</a> <a href="#" class="list-group-item">
						<h4 class="list-group-item-heading list-group-item-success">ORDINI
							ULTIMATI</h4>
						<p class="list-group-item-text">Gli ordini da inviare al fornitore
							o al tesoriere</p>
					</a>
				</section>
				<div id=saldo class="hidden-sm visible-md-inline visible-lg-inline">
				<h3>Saldo: &euro; <span name="label_saldo" class="label label-success"><?php echo $saldo;?></span></h3>
				<button id=ricarica2 href="#ricarica" onclick="richiedi('../ricarica/ricarica.php');" type="button" class="btn btn-default btn-sm btn-warning"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"> Ricarica</button>
				
				</div>
				<div id=saldo_piccoli_schermi class="visible-sm-inline">
				<h3 >Saldo: &euro; <span name="label_saldo" class="label label-success" onload=check_label_saldo(this)> <?php echo $saldo;?></span></h3>
				<button id=ricarica1 type="button" class="btn btn-default btn-sm btn-warning">Ricarica   <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></button>
				</div>
				<div id=saldo_schermi_molto_piccoli class="visible-xs-block">
				<h3>Saldo: &euro; <span name="label_saldo" class="label label-success" onload=check_label_saldo(this)> <?php echo $saldo;?></span></h3>
				<button id=ricarica2 type="button" class="btn btn-default btn-sm btn-warning"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"> Ricarica</button>
				
				</div>
				</div>
			<!-- fine sezione listini ultimati -->
		</div>
		<!-- fine riga -->

	</div>
	<!-- fine container globale -->
<script type="text/javascript">
check_role();
</script>
</body>
</html>

<?php
} else {
	header ( "Location: ../login/login.php" );
	// echo 'You are not authorized to access this page, please login. <br/>';
}
?>
